package com.ruoyi.info.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.CmsNav;
import com.ruoyi.info.service.ICmsNavService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 导航栏Controller
 * 
 * @author xwj
 * @date 2023-07-06
 */
@Controller
@RequestMapping("/info/nav")
public class CmsNavController extends BaseController
{
    private String prefix = "info/nav";

    @Autowired
    private ICmsNavService cmsNavService;

    @GetMapping()
    public String nav()
    {
        return prefix + "/nav";
    }

    /**
     * 查询导航栏列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsNav cmsNav)
    {
        startPage();
        List<CmsNav> list = cmsNavService.selectCmsNavList(cmsNav);
        return getDataTable(list);
    }

    /**
     * 导出导航栏列表
     */
    @Log(title = "导航栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsNav cmsNav)
    {
        List<CmsNav> list = cmsNavService.selectCmsNavList(cmsNav);
        ExcelUtil<CmsNav> util = new ExcelUtil<CmsNav>(CmsNav.class);
        return util.exportExcel(list, "导航栏数据");
    }

    /**
     * 新增导航栏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存导航栏
     */
    @Log(title = "导航栏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsNav cmsNav)
    {
        return toAjax(cmsNavService.insertCmsNav(cmsNav));
    }

    /**
     * 修改导航栏
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsNav cmsNav = cmsNavService.selectCmsNavById(id);
        mmap.put("cmsNav", cmsNav);
        return prefix + "/edit";
    }

    /**
     * 修改保存导航栏
     */
    @Log(title = "导航栏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsNav cmsNav)
    {
        return toAjax(cmsNavService.updateCmsNav(cmsNav));
    }

    /**
     * 删除导航栏
     */
    @Log(title = "导航栏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsNavService.deleteCmsNavByIds(ids));
    }
}
